package org.kfive.nova.algorithm.sort;

/**
 * Created with IntelliJ IDEA.
 * User: admin
 * Date: 14-5-13
 * Time: 上午10:20
 * To change this template use File | Settings | File Templates.
 */
public class ShellSort {

    public static void shellSort(int [] source,int d){
        for(int i=d;i<source.length;i++){
            int j=i;
            int s= source[i];
            for(j=i-d;j>=0&&(s<source[j]);j-=d){
                source[j+d] = source[j];
            }
            source[j+d]=s;
        }
    }


    public static void main(String [] args){
        int [] source = {8,3,6,8,1,2,0,4,1,56,78,123,45,98};
        int [] len = {5,3,1};
        for (int i=0;i<len.length;i++){
            shellSort(source,len[i]);
        }
        for (int i=0;i<source.length;i++){
            System.out.println(source[i]);
        }
    }
}
